var t = getApp();

Page({
    data: {
        language: "",
        dataList: [],
        numberRounds: 0,
        member: {},
        titleArr: [ "抢团中", "抢团中奖", "抢团失败" ],
        active: 0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        showBarter: !1,
        showBarter_value: null,
        orderPayId: null
    },
    onLoad: function(t) {},
    onShow: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        }), this.getdata();
    },
    handleClick: function(t) {
        this.setData({
            dataList: [],
            active: t.detail.index
        }), this.getdata();
    },
    getdata: function() {
        var a = this, e = t.getNetAddresss("plugin.snatch-regiment.api.index.getSnatchData");
        t._getNetWork({
            url: e,
            data: {
                art: "myTeam",
                state: a.data.active + 1
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    isLoadMore: !0,
                    page: 1,
                    total_page: e.data.myTeam.list.last_page,
                    dataList: e.data.myTeam.list.data,
                    member: e.data.myTeam.member,
                    numberRounds: e.data.myTeam.numberRounds
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    gotoRecord: function() {
        wx.navigateTo({
            url: "/packageE/grab_group/grab_group_my_record/grab_group_my_record"
        });
    },
    gotoOrderDetail: function(t) {
        var a = t.target.dataset.id || t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/member/orderdetail/orderdetail?order_id=" + a + "&orderType=grabGroup"
        });
    },
    gotoGroup: function(t) {
        var a = t.target.dataset.id || t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageE/grab_group/grab_group_detail/grab_group_detail?&id=" + a
        });
    },
    operation: function(t) {
        var a = t.currentTarget.dataset.data, e = t.currentTarget.dataset.barter, r = {
            id: t.currentTarget.dataset.orderid
        };
        this.setData({
            orderPayId: r.id
        }), 8 == a.value || "snatch_regiment_express" == a.value ? this.checklogistics(r, a) : 10 == a.value ? this.comment(r, a) : 1 == a.value || "snatch_regiment_pay" == a.value ? this.toPay(r, a) : 13 == a.value || "snatch_regiment_refund" == a.value ? this.getTemplate(r, a) : 18 == a.value ? this.toRefundDetail(r, a) : 3 == a.value ? this.gotoRefund(r.id) : 40 == a.value ? this.gotoRefundCheck(r.id) : "snatch_regiment_barter" == a.value ? this.setData({
            showBarter: !0,
            showBarter_value: e
        }) : this.publicMessage(a, r);
    },
    confirmBarter: function() {
        var a = t.getNetAddresss("plugin.snatch-regiment.api.order.barter");
        a += "&order_id=" + this.data.orderPayId, t._getNetWork({
            url: a,
            success: function(t) {
                var a = t.data;
                1 == a.result ? (wx.showToast({
                    title: "易货兑换成功",
                    icon: "success",
                    duration: 1500,
                    success: function() {}
                }), that.getdata()) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1200
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    cancelBarter: function() {
        this.setData({
            showBarter: !1,
            showBarter_value: null
        });
    },
    publicMessage: function(a, e) {
        console.log(a);
        var r = this;
        a.api && wx.showModal({
            title: "提示",
            content: "确定".concat(a.name, "?"),
            success: function(o) {
                if (o.confirm) {
                    var n = "";
                    n += t.getNetAddresss(a.api), n += "&order_id=" + e.id, t._getNetWork({
                        url: n,
                        success: function(t) {
                            var e = t.data;
                            1 == e.result ? (r.getdata(), wx.showToast({
                                title: "".concat(a.name, "成功"),
                                icon: "success",
                                duration: 1500,
                                success: function() {}
                            })) : wx.showToast({
                                icon: "none",
                                title: e.msg,
                                duration: 1e3
                            });
                        },
                        fail: function(t) {
                            console.log(t);
                        }
                    });
                }
            }
        });
    },
    checklogistics: function(t, a) {
        wx.navigateTo({
            url: "/packageA/member/order/logistics/logistics?id=" + t.id + "&api=" + a.api
        });
    },
    comment: function(t, a) {
        wx.navigateTo({
            url: "/packageB/member/comment/comment?order=" + JSON.stringify(t || {})
        });
    },
    toPay: function(t, a) {
        wx.navigateTo({
            url: "/packageD/buy/orderPay/orderPay?order_id=" + t.id + "&status=2&api=" + a.api
        });
    },
    getTemplate: function(a, e) {
        var r = t.getNetAddresss("member.member.getMiniTemplateCorrespond"), o = this;
        t._getNetWork({
            url: r,
            data: {
                small_type: 2
            },
            success: function(t) {
                var r = t.data;
                if (1 == r.result) {
                    for (var n = [], i = 0; i < r.data.length; i++) n.push(r.data[i].template_id);
                    o.setData({
                        TemplateArray: n
                    }), wx.requestSubscribeMessage({
                        tmplIds: o.data.TemplateArray,
                        success: function(t) {
                            o._toRefund(a, e);
                        },
                        fail: function() {
                            o._toRefund(a, e);
                        }
                    });
                } else wx.showToast({
                    title: r.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    _toRefund: function(t, a) {
        wx.navigateTo({
            url: "/packageD/member/myOrder/refund/refund?order_id=" + t.id + "&type=3"
        });
    },
    toRefundDetail: function(t, a) {
        wx.navigateTo({
            url: "packageD/member/myOrder/Aftersales/Aftersales?refund_id=" + t.refund_id
        });
    },
    gotoRefund: function(t) {
        wx.navigateTo({
            url: "/packageB/member/OrderReturn/OrderReturn?id=" + t
        });
    },
    gotoRefundCheck: function(t) {
        wx.navigateTo({
            url: "/packageB/member/OrderReturnCheck/OrderReturnCheck?id=" + t
        });
    },
    onReady: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    _getMoreData: function() {
        var a = this, e = {}, r = "", o = "";
        a.data.isLoadMore = !1, this.data.page >= this.data.total_page || (this.data.page = this.data.page + 1, 
        r = "plugin.snatch-regiment.api.index.getSnatchData", e = {
            page: a.data.page,
            art: "myTeam",
            state: a.data.active + 1
        }, o = t.getNetAddresss(r), t._postNetWork({
            url: o,
            showToastIn: !1,
            data: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    isLoadMore: !0,
                    dataList: a.data.dataList.concat(e.data.myTeam.list.data)
                }) : a.setData({
                    page: a.data.page - 1,
                    isLoadMore: !1
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        }));
    },
    onShareAppMessage: function() {}
});